package com.gangan.controller.web;

import com.gangan.controller.common.BaseController;
import com.gangan.model.Patient;
import com.gangan.service.IOrderService;
import com.gangan.service.IPatientService;
import com.gangan.tools.MessageBean;
import io.lettuce.core.dynamic.annotation.Param;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


/**
 * 就诊人(患者控制层)
 * @author wuyunhu
 */
@Api(value = "/patient",description = "*就诊人(患者)管理模块")
@RestController
@RequestMapping("/patient")
public class PatientController extends BaseController {

    @Autowired
    IOrderService orderService;

    @Autowired
    IPatientService patientService;

    @RequestMapping(value = "/addPatient",method = RequestMethod.POST)
    @ApiOperation(value="预约填写/选择候诊人", notes="新增候诊人")
    public MessageBean addPatient(Patient patient){
        try{
            patientService.addPatient(patient);
        }catch(Exception e){
            return   resultFailed();
        }
        return  resultSuccess();
    }

    @RequestMapping(value = "/getPatient",method = RequestMethod.GET)
    @ApiOperation(value="选择候选人", notes="返回该代理人的候诊人列表")
    public MessageBean getPatientByUser(@Param(value="userId")Integer userId){
        try{
            return  resultSuccess(patientService.getPatientByUser(userId));
        }catch(Exception e){
            return   resultFailed();
        }
    }

    @RequestMapping(value = "/getPatientList",method = RequestMethod.GET)
    @ApiOperation(value="就诊人管理", notes="显示所有患者")
    public MessageBean getPatientByUser(){
        try{
            return  resultSuccess(patientService.getPatientList());
        }catch(Exception e){
            return   resultFailed();
        }
    }

    @RequestMapping(value = "/getPatientByWhere",method = RequestMethod.POST)
    @ApiOperation(value="就诊人管理", notes="根据姓名或证件或年龄查询患者")
    public MessageBean getListByWhere(String param){
        if(StringUtils.isEmpty(param)){
            return resultSuccess(patientService.getPatientList());
        }else{
            return resultSuccess(patientService.getListByWhere(param));
        }
    }

    @RequestMapping(value = "/disDoctor",method = RequestMethod.POST)
    @ApiOperation(value="就诊人管理", notes="分配医生" )
    public MessageBean disDoctor(Integer customerId,Integer doctorId,String doctorName){
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("customerId",customerId );
        map.put("doctorId",doctorId );
        map.put("doctorName",doctorName );
        try{
            patientService.disDoctor(map);
            return  resultSuccess();
        }catch(Exception e){
            return resultFailed();
        }
    }






}
